﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Text;
using WebUI.Model;
using System.Net.Mail;

namespace WebUI.Controllers
{
    public class QuotationController : Controller
    {
        public ActionResult Index()
        {
            return View();
        }
        [HttpPost]
        public ActionResult Index(Quotation quotation)
        {
            if (ModelState.IsValid)
            {
                SendEmailToTapfreaks(quotation);
                SendEmailToClient(quotation);
                return View("Thanks");
            }
            return View(quotation);
        }
        private void SendEmailToClient(Quotation quotation)
        {
            try
            {
                MailMessage message = new MailMessage();
                message.From = new MailAddress("info@tapfreaks.net");
                message.To.Add(new MailAddress(quotation.Email));
                message.Subject = "Thankyou for proposal request";
                message.Body = " Thankyou; this is mail message is send to you, to inform you that your request for proposal has been sent to tapfreaks team";
                GlobalController.SendEmail(message);
            }
            catch (Exception ex)
            {
                // Response.Write(ex.Message);

            }
        }
        private void SendEmailToTapfreaks(Quotation quotation)
        {
            StringBuilder body = new StringBuilder();
            try
            {
                MailMessage message = new MailMessage();
                message.From = new MailAddress("info@tapfreaks.net");
                message.To.Add(new MailAddress("developer.asif@gmail.com"));
                message.Subject = quotation.Name + " Contacted for proposal request";

                body.AppendLine("Name = " + quotation.Name);
                body.AppendLine();
                body.AppendLine("Email = " + quotation.Email);
                body.AppendLine();
                body.AppendLine("Phone = " + quotation.Phone);
                body.AppendLine();
                body.AppendLine("Service = " + quotation.Service);
                body.AppendLine();
                body.AppendLine("ProjectType = " + quotation.ProjectType);
                body.AppendLine();
                body.AppendLine("Additional Information = " + quotation.Message);
                body.AppendLine();
                message.Body = body.ToString();
                GlobalController.SendEmail(message);
            }
            catch (Exception ex)
            {
                // Response.Write(ex.Message);

            }
        }



        public ActionResult SpecialOffer()
        {
            return View();
        }
        [HttpPost]
        public ActionResult SpecialOffer(SpecialOffer specialOffer)
        {
            if (ModelState.IsValid)
            {
                SendEmailToTapfreaksSO(specialOffer);
                SendEmailToClientSO(specialOffer);
                return View("Thanks");
            }
            return View(specialOffer);
        }

        private void SendEmailToClientSO(SpecialOffer specialOffer)
        {
            StringBuilder body = new StringBuilder();
            try
            {
                MailMessage message = new MailMessage();
                message.From = new MailAddress("info@tapfreaks.net");
                message.To.Add(new MailAddress(specialOffer.Email));
                message.Subject = "Thankyou for choosing our special offer";
                
                body.AppendLine("Thankyou; this is mail message is send to you, to inform you that your request for proposal has been sent to tapfreaks team");
                body.AppendLine("Your offer details are as below:");
                body.AppendLine();
                body.AppendLine("--------------------------------------------------------------");
                int total = 0;
                body.AppendLine();
                body.AppendLine("Your Default Features Are :");
                body.AppendLine("-----------------"); 
                body.AppendLine("RSS Feeds");
                body.AppendLine("Custom Design");
                body.AppendLine("Five Custom Views");
                body.AppendLine("AppStore Publishing");
                body.AppendLine();
                body.AppendLine();
                body.AppendLine();
                body.AppendLine("Your Extra Features and their amounts Are :");
                body.AppendLine("-----------------"); 
                
                if (specialOffer.IsGEOLocation)
                {
                    body.AppendLine("Geolocation : $20");
                    total = total + 20;
                }

                if (specialOffer.IsPictureGallery)
                {
                    body.AppendLine("Picture Gallery : $16");
                    total = total + 16;
                }

                if (specialOffer.IsPublishing)
                {
                    body.AppendLine("Publishing : $41");
                    total = total + 41;
                }


                if (specialOffer.IsVideoStreaming)
                {
                    body.AppendLine("Video Streaming : $60");
                    total = total + 60;
                }

                body.AppendLine("-----------------");                
                body.AppendLine("Extra Features Total Amount is : $" + total.ToString());
                body.AppendLine("Amount of Default Features is : $99");
                body.AppendLine("------------------");
                body.AppendLine();
                body.AppendLine("Your net amount is : $" + (total + 99).ToString());

                message.Body = body.ToString();                
                GlobalController.SendEmail(message);
            }
            catch (Exception ex)
            {
                // Response.Write(ex.Message);

            }
        }
        private void SendEmailToTapfreaksSO(SpecialOffer specialOffer)
        {
            StringBuilder body = new StringBuilder();
            try
            {
                MailMessage message = new MailMessage();
                message.From = new MailAddress("info@tapfreaks.net");
                message.To.Add(new MailAddress("developer.asif@gmail.com"));
                message.Subject = specialOffer.Name + " Contacted For Special Offer";
                body.AppendLine();
                body.AppendLine("Following client has choosen our special offer");
                body.AppendLine();
                body.AppendLine("Name = " + specialOffer.Name);
                body.AppendLine();
                body.AppendLine("Email = " + specialOffer.Email);
                body.AppendLine();
                body.AppendLine("Phone = " + specialOffer.Phone);
                body.AppendLine();
                body.AppendLine("Additional Information = " + specialOffer.Message);
                body.AppendLine();
                body.AppendLine("===================================================");
                body.AppendLine();
                body.AppendLine("Extra Features");
                body.AppendLine("================");
                body.AppendLine();
                int total = 0;

                if (specialOffer.IsGEOLocation)
                {
                    body.AppendLine("Geolocation : $20");
                    total = total + 20;
                }

                if (specialOffer.IsPictureGallery)
                {
                    body.AppendLine("Picture Gallery : $16");
                    total = total + 16;
                }

                if (specialOffer.IsPublishing)
                {
                    body.AppendLine("Publishing : $41");
                    total = total + 41;
                }


                if (specialOffer.IsVideoStreaming)
                {
                    body.AppendLine("Video Streaming : $60");
                    total = total + 60;
                }
                body.AppendLine("==========================");
                body.AppendLine("Total Amount is : $" + total.ToString());


                message.Body = body.ToString();
                GlobalController.SendEmail(message);
            }
            catch (Exception ex)
            {
                // Response.Write(ex.Message);

            }
        }

    }
}
